package personal.xjl._23java1studentdemo.mapper;

import org.apache.ibatis.annotations.*;
import personal.xjl._23java1studentdemo.model.Course;
import personal.xjl._23java1studentdemo.model.Student;
import personal.xjl._23java1studentdemo.model.Teacher;

import java.util.List;

@Mapper
public interface TeacherMapper {

    @Select("select * from teacher")
    List<Teacher> selectAll();

    @Delete("delete from teacher where id =#{id}")
    int delete(int id);

    @Insert("insert into teacher( id,name, password, sex, birthday, course_id, professional) values (#{id},#{name},#{password},#{sex},#{birthday},#{course_id},#{professional})")
    int insert(Teacher teacher);


    @Select("select * from teacher where id=#{id}")
    Teacher selectById(int id);

    @Update("update teacher set name=#{name},password=#{password},sex=#{sex},birthday=#{birthday},course_id=#{course_id}, professional=#{professional} where id =#{id}")
    int update(Teacher teacher);

    @Select("select * from teacher limit #{fromIndex},#{pageSize}")
    @Results({
            @Result(column = "course_id",property = "course",javaType = Course.class,
            one = @One(select ="personal.xjl._23java1studentdemo.mapper.CourseMapper.findById"))
    })
    List<Teacher> selectByPage(int fromIndex, int pageSize);

    @Select("select * from teacher where name=#{username} and password =#{password}")
    Teacher selectByNameAndPwd(String username, String password);
}
